package trading.ctm.yunjing.module.login.activity

import android.os.Bundle
import android.text.TextUtils
import cc.vv.baselibrary.activity.BaseActivity
import cc.vv.baselibrary.util.LKToastUtil
import cc.vv.baselibrary.view.BaseTopBarView
import kotlinx.android.synthetic.main.activity_forget.*
import trading.ctm.yunjing.R
import trading.ctm.yunjing.util.*

/**
 * @desc 忘记密码
 * @author zouxiaorui
 * @date  2018/8/8
 */
class ForgetActivity : BaseActivity() {

    private var mPhoneNumber = ""
    private var mCode = ""
    private var mPassword = ""

    override fun initLayoutRes(): Int {
        return R.layout.activity_forget
    }

    override fun initAction(data: Bundle?) {
        super.initAction(data)

        btbv_af_forget_password.setEventInterface(object : BaseTopBarView.EventInterface{
            override fun leftOnClick() {
                finish()
            }

            override fun leftCloseClick() {
            }

            override fun rightOnClick() {
            }

        })

        //手机号
        phoneChange(tiet_af_phone_number, tiet_af_code, tiet_af_setting_password, iv_af_checkout_phone, tv_af_finsh)
        //验证码
        codeChange(tiet_af_code, tiet_af_phone_number, tiet_af_setting_password, tv_af_finsh)
        //密码
        passwordChange(tiet_af_setting_password, tiet_af_phone_number, tiet_af_code, tv_af_finsh)

        //获取验证码
        tv_af_obtain_code.setOnClickListener {
            mPhoneNumber = tiet_af_phone_number.text.toString()
            obtainCode(mPhoneNumber)

        }
        //完成
        tv_af_finsh.setOnClickListener {
            mPhoneNumber = tiet_af_phone_number.text.toString()
            mCode = tiet_af_code.text.toString()
            mPassword = tiet_af_setting_password.text.toString()
            if (isPhoneNumber(mPhoneNumber) && isCode(mCode) && isPassword(mPassword)) {
                settingPasswordFinsh(mPhoneNumber, mCode, mPassword)
            } else if (!isPhoneNumber(mPhoneNumber)) {
                LKToastUtil.showToastShort("请输入正确的手机号码")
            } else if (TextUtils.isEmpty(mCode)) {
                LKToastUtil.showToastShort("验证码不正确")
            } else if (isPassword(mPassword)) {
                LKToastUtil.showToastShort("密码格式不正确")
            }
        }
    }

    private fun settingPasswordFinsh(phone: String, code: String, password: String) {
        LKToastUtil.showToastShort("更改密码成功")
    }

    private fun obtainCode(phone: String) {
        if (isPhoneNumber(phone)) {
            countDownTime(tv_af_obtain_code, 60000L, "s")
        } else {
            LKToastUtil.showToastShort("请输入正确手机号")
        }
    }


}